<template>
  <div class="patient-services-page">
    <div class="page-header">
      <div class="container">
        <h1 class="page-title">患者服务</h1>
        <el-breadcrumb separator="/">
          <el-breadcrumb-item :to="{ path: '/portal' }">首页</el-breadcrumb-item>
          <el-breadcrumb-item>患者服务</el-breadcrumb-item>
        </el-breadcrumb>
      </div>
    </div>
    
    <!-- 主要内容 -->
    <div class="container main-content">
      <el-row :gutter="30">
        <!-- 左侧导航 -->
        <el-col :xs="24" :sm="24" :md="6" :lg="6" :xl="5">
          <div class="side-nav">
            <h3 class="side-nav-title">患者服务</h3>
            <el-menu
              class="side-menu"
              :default-active="activeMenu"
              @select="handleMenuSelect"
            >
              <el-menu-item index="appointment">
                <el-icon><Calendar /></el-icon>
                <span>预约挂号</span>
              </el-menu-item>
              <el-menu-item index="appointments">
                <el-icon><List /></el-icon>
                <span>我的预约</span>
              </el-menu-item>
              <el-menu-item index="records">
                <el-icon><Document /></el-icon>
                <span>就诊记录</span>
              </el-menu-item>
              <el-menu-item index="reports">
                <el-icon><DataAnalysis /></el-icon>
                <span>检查报告</span>
              </el-menu-item>
              <el-menu-item index="prescriptions">
                <el-icon><List /></el-icon>
                <span>处方查询</span>
              </el-menu-item>
              <el-menu-item index="bills">
                <el-icon><Money /></el-icon>
                <span>费用查询</span>
              </el-menu-item>
            </el-menu>
            
            <!-- 服务热线卡片 -->
            <div class="service-card">
              <h4 class="service-card-title">
                <el-icon><Service /></el-icon>
                服务热线
              </h4>
              <p class="service-phone">123-456-7890</p>
              <p class="service-time">周一至周日 8:00-18:00</p>
            </div>
          </div>
        </el-col>
        
        <!-- 右侧服务概览 -->
        <el-col :xs="24" :sm="24" :md="18" :lg="18" :xl="19">
          <div class="services-overview">
            <!-- 欢迎区域 -->
            <div class="welcome-section">
              <el-card class="welcome-card">
                <div class="welcome-content">
                  <div class="welcome-text">
                    <h2>欢迎使用患者服务平台</h2>
                    <p>为您提供便捷的医疗服务，让就医更简单</p>
                  </div>
                  <div class="welcome-avatar">
                    <el-avatar :size="80" :src="userStore.userInfo?.avatar">
                      <el-icon><User /></el-icon>
                    </el-avatar>
                    <p class="user-name">{{ userStore.userInfo?.name || userStore.userInfo?.username || '用户' }}</p>
                  </div>
                </div>
              </el-card>
            </div>
            
            <!-- 快捷服务 -->
            <div class="quick-services">
              <h3 class="section-title">快捷服务</h3>
              <el-row :gutter="20">
                <el-col :xs="12" :sm="8" :md="6" :lg="4">
                  <el-card class="service-item" shadow="hover" @click="handleNavigation('appointment')">
                    <div class="service-icon">
                      <el-icon><Calendar /></el-icon>
                    </div>
                    <h4>预约挂号</h4>
                    <p>在线预约专家号</p>
                  </el-card>
                </el-col>
                
                <el-col :xs="12" :sm="8" :md="6" :lg="4">
                  <el-card class="service-item" shadow="hover" @click="handleNavigation('appointments')">
                    <div class="service-icon">
                      <el-icon><List /></el-icon>
                    </div>
                    <h4>我的预约</h4>
                    <p>查看预约记录</p>
                  </el-card>
                </el-col>
                
                <el-col :xs="12" :sm="8" :md="6" :lg="4">
                  <el-card class="service-item" shadow="hover" @click="handleNavigation('records')">
                    <div class="service-icon">
                      <el-icon><Document /></el-icon>
                    </div>
                    <h4>就诊记录</h4>
                    <p>查看病历档案</p>
                  </el-card>
                </el-col>
                
                <el-col :xs="12" :sm="8" :md="6" :lg="4">
                  <el-card class="service-item" shadow="hover" @click="handleNavigation('reports')">
                    <div class="service-icon">
                      <el-icon><DataAnalysis /></el-icon>
                    </div>
                    <h4>检查报告</h4>
                    <p>查看检验结果</p>
                  </el-card>
                </el-col>
                
                <el-col :xs="12" :sm="8" :md="6" :lg="4">
                  <el-card class="service-item" shadow="hover" @click="handleNavigation('prescriptions')">
                    <div class="service-icon">
                      <el-icon><List /></el-icon>
                    </div>
                    <h4>处方查询</h4>
                    <p>查看用药记录</p>
                  </el-card>
                </el-col>
                
                <el-col :xs="12" :sm="8" :md="6" :lg="4">
                  <el-card class="service-item" shadow="hover" @click="handleNavigation('bills')">
                    <div class="service-icon">
                      <el-icon><Money /></el-icon>
                    </div>
                    <h4>费用查询</h4>
                    <p>查看医疗费用</p>
                  </el-card>
                </el-col>
              </el-row>
            </div>
            
            <!-- 服务统计 -->
            <div class="service-stats">
              <h3 class="section-title">服务统计</h3>
              <el-row :gutter="20">
                <el-col :xs="12" :sm="6" :md="6" :lg="6">
                  <el-card class="stat-card">
                    <div class="stat-content">
                      <div class="stat-number">{{ stats.totalAppointments }}</div>
                      <div class="stat-label">总预约次数</div>
                    </div>
                    <div class="stat-icon appointment">
                      <el-icon><Calendar /></el-icon>
                    </div>
                  </el-card>
                </el-col>
                
                <el-col :xs="12" :sm="6" :md="6" :lg="6">
                  <el-card class="stat-card">
                    <div class="stat-content">
                      <div class="stat-number">{{ stats.totalRecords }}</div>
                      <div class="stat-label">就诊记录</div>
                    </div>
                    <div class="stat-icon record">
                      <el-icon><Document /></el-icon>
                    </div>
                  </el-card>
                </el-col>
                
                <el-col :xs="12" :sm="6" :md="6" :lg="6">
                  <el-card class="stat-card">
                    <div class="stat-content">
                      <div class="stat-number">{{ stats.totalReports }}</div>
                      <div class="stat-label">检查报告</div>
                    </div>
                    <div class="stat-icon report">
                      <el-icon><DataAnalysis /></el-icon>
                    </div>
                  </el-card>
                </el-col>
                
                <el-col :xs="12" :sm="6" :md="6" :lg="6">
                  <el-card class="stat-card">
                    <div class="stat-content">
                      <div class="stat-number">{{ stats.totalPrescriptions }}</div>
                      <div class="stat-label">处方记录</div>
                    </div>
                    <div class="stat-icon prescription">
                      <el-icon><List /></el-icon>
                    </div>
                  </el-card>
                </el-col>
              </el-row>
            </div>
            
            <!-- 最近活动 -->
            <div class="recent-activities">
              <h3 class="section-title">最近活动</h3>
              <el-card>
                <el-timeline>
                  <el-timeline-item
                    v-for="(activity, index) in recentActivities"
                    :key="index"
                    :timestamp="activity.time"
                    :type="activity.type"
                  >
                    <div class="activity-content">
                      <h4>{{ activity.title }}</h4>
                      <p>{{ activity.description }}</p>
                    </div>
                  </el-timeline-item>
                </el-timeline>
              </el-card>
            </div>
          </div>
        </el-col>
      </el-row>
    </div>
  </div>
</template>

<script setup>
import { ref, reactive, onMounted } from 'vue'
import { useRouter } from 'vue-router'
import { useUserStore } from '@/stores/user'
import { Calendar, List, Document, DataAnalysis, Money, Service, User } from '@element-plus/icons-vue'

const router = useRouter()
const userStore = useUserStore()

// 当前激活的菜单项
const activeMenu = ref('services')

// 服务统计数据
const stats = reactive({
  totalAppointments: 12,
  totalRecords: 8,
  totalReports: 15,
  totalPrescriptions: 6
})

// 最近活动数据
const recentActivities = ref([
  {
    title: '血常规检查报告已出',
    description: '您的血常规检查报告已经出来，请及时查看',
    time: '2024-01-16 14:30',
    type: 'primary'
  },
  {
    title: '预约成功',
    description: '您已成功预约张医生1月18日上午的门诊',
    time: '2024-01-15 10:20',
    type: 'success'
  },
  {
    title: '处方已开具',
    description: '张医生为您开具了新的处方，请按时取药',
    time: '2024-01-15 09:45',
    type: 'info'
  },
  {
    title: '费用已支付',
    description: '您的门诊费用已支付成功',
    time: '2024-01-15 09:30',
    type: 'success'
  }
])

// 菜单选择处理
const handleMenuSelect = (key) => {
  const routes = {
    'appointment': '/portal/patient/appointment',
    'appointments': '/portal/patient/appointments',
    'records': '/portal/patient/records',
    'reports': '/portal/patient/reports',
    'prescriptions': '/portal/patient/prescription',
    'bills': '/portal/patient/payment'
  }
  
  if (routes[key]) {
    router.push(routes[key])
  }
}

// 导航处理
const handleNavigation = (service) => {
  handleMenuSelect(service)
}

// 加载用户数据
const loadUserData = async () => {
  // 这里可以加载用户的服务统计数据
  // 暂时使用模拟数据
  console.log('加载用户服务数据')
}

onMounted(() => {
  loadUserData()
})
</script>

<style scoped>
.patient-services-page {
  background-color: #f5f7fa;
  min-height: 100vh;
  padding-bottom: 40px;
}

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 20px;
}

.page-header {
  background-color: white;
  padding: 20px 0;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
  margin-bottom: 30px;
}

.page-title {
  font-size: 24px;
  color: #333;
  margin: 0 0 10px;
}

.main-content {
  gap: 30px;
}

/* 左侧导航样式 */
.side-nav {
  background: white;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.1);
}

.side-nav-title {
  background: linear-gradient(135deg, #1989fa 0%, #1976d2 100%);
  color: white;
  margin: 0;
  padding: 20px;
  font-size: 18px;
  font-weight: 600;
  text-align: center;
}

.side-menu {
  border-right: none;
}

.service-card {
  margin-top: 20px;
  padding: 20px;
  background: #f8f9fa;
  border-top: 1px solid #ebeef5;
}

.service-card-title {
  font-size: 16px;
  color: #1989fa;
  margin: 0 0 15px;
  display: flex;
  align-items: center;
}

.service-card-title .el-icon {
  margin-right: 8px;
}

.service-phone {
  font-size: 18px;
  font-weight: bold;
  color: #1989fa;
  margin: 0 0 5px;
}

.service-time {
  font-size: 14px;
  color: #666;
  margin: 0;
}

/* 右侧内容样式 */
.services-overview {
  display: flex;
  flex-direction: column;
  gap: 30px;
}

/* 欢迎区域 */
.welcome-card {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  border: none;
  color: white;
}

.welcome-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.welcome-text h2 {
  margin: 0 0 10px;
  font-size: 24px;
}

.welcome-text p {
  margin: 0;
  font-size: 16px;
  opacity: 0.9;
}

.welcome-avatar {
  text-align: center;
}

.user-name {
  margin: 10px 0 0;
  font-size: 16px;
  font-weight: 600;
}

/* 快捷服务 */
.section-title {
  font-size: 20px;
  color: #333;
  margin: 0 0 20px;
  font-weight: 600;
}

.service-item {
  text-align: center;
  cursor: pointer;
  transition: all 0.3s ease;
  border: 2px solid transparent;
}

.service-item:hover {
  transform: translateY(-5px);
  border-color: #1989fa;
  box-shadow: 0 8px 25px rgba(0, 0, 0, 0.15);
}

.service-icon {
  width: 60px;
  height: 60px;
  margin: 0 auto 15px;
  background: linear-gradient(135deg, #1989fa, #1976d2);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 28px;
}

.service-item h4 {
  margin: 0 0 8px;
  color: #333;
  font-size: 16px;
  font-weight: 600;
}

.service-item p {
  margin: 0;
  color: #666;
  font-size: 14px;
}

/* 服务统计 */
.stat-card {
  position: relative;
  overflow: hidden;
}

.stat-content {
  position: relative;
  z-index: 2;
}

.stat-number {
  font-size: 32px;
  font-weight: bold;
  color: #333;
  margin-bottom: 5px;
}

.stat-label {
  font-size: 14px;
  color: #666;
}

.stat-icon {
  position: absolute;
  right: 20px;
  top: 50%;
  transform: translateY(-50%);
  width: 60px;
  height: 60px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  color: white;
  opacity: 0.8;
}

.stat-icon.appointment {
  background: linear-gradient(135deg, #1989fa, #1976d2);
}

.stat-icon.record {
  background: linear-gradient(135deg, #67c23a, #85ce61);
}

.stat-icon.report {
  background: linear-gradient(135deg, #e6a23c, #f56c6c);
}

.stat-icon.prescription {
  background: linear-gradient(135deg, #909399, #606266);
}

/* 最近活动 */
.activity-content h4 {
  margin: 0 0 5px;
  color: #333;
  font-size: 16px;
}

.activity-content p {
  margin: 0;
  color: #666;
  font-size: 14px;
}

/* 响应式设计 */
@media (max-width: 768px) {
  .welcome-content {
    flex-direction: column;
    text-align: center;
    gap: 20px;
  }
  
  .service-item {
    margin-bottom: 15px;
  }
  
  .stat-card {
    margin-bottom: 15px;
  }
}
</style> 